/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models.beans;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
/**
 *
 * @author Hoang Dong Tien
 */
public class User extends org.apache.struts.action.ActionForm {

    private int userId;
    private String username;
    private String password;
    private String fullname;
    private Date birthday;
    private String role;
    private String gender;
    private String address;
    private String mobile;
    private String email;
    private String profileImage;
    public static final String ROLE_ADMIN = "admin";
    public static final String ROLE_EMPLOYEE = "employee";
    public static final String GENDER_MALE = "male";
    public static final String GENDER_FEMALE = "female";
    public static final String GENDER_OTHERS = "others";

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday_sql(Date birthday) {
        this.birthday = birthday;
    }
    public void setBirthday(String birthday) throws ParseException{
        Date date = SimpleDateFormat.getDateInstance().parse(birthday);
        this.birthday = date;
    }
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public String getGender() {
        return gender.toLowerCase();
    }

    public void setGender(String gender) {
           if (gender.equalsIgnoreCase(User.GENDER_FEMALE)
                || role.equalsIgnoreCase(User.GENDER_MALE)
                || role.equalsIgnoreCase(User.GENDER_OTHERS)
           ) {
            this.gender = gender.toLowerCase();
        } 
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getProfileImage() {
        return profileImage;
    }

    public void setProfileImage(String profileImage) {
        this.profileImage = profileImage;
    }

    public String getRole() {
        return role.toLowerCase();
    }

    public void setRole(String role) {
        if (role.equalsIgnoreCase(User.ROLE_ADMIN) || role.equalsIgnoreCase(User.ROLE_EMPLOYEE)) {
            this.role = role.toLowerCase();
        }
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public java.sql.Date getBirthdaySql() {
        return new java.sql.Date(this.birthday.getTime());
    }

    public User() {
        super();
        this.address = "";
        this.birthday = new Date();
        this.email = "";
        this.fullname = "";
        this.gender = User.GENDER_MALE;
        this.mobile = "";
        this.password = "";
        this.profileImage = "";
        this.role = User.ROLE_EMPLOYEE;
        this.userId = 0;
        this.username = "";
    }

     @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();

        return errors;
    }
}
